package com.yunfei.practice_mybatis.web.dao;

import com.yunfei.practice_mybatis.web.dataobject.ZhangyunfeiAccountingRecord;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

@Mapper
public interface ZhangyunfeiAccountingRecordMapper {
    @Delete({
            "delete from zhangyunfei_accounting_record",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(  Long id);

    @Insert({
            "insert into zhangyunfei_accounting_record ( gmt_created, ",
            "gmt_modified, record_time, ",
            "amount, type, category, ",
            "`desc`)",
            "values ( now(), ",
            "now(), #{recordTime,jdbcType=VARCHAR}, ",
            "#{amount,jdbcType=DOUBLE}, #{type,jdbcType=VARCHAR}, #{category,jdbcType=VARCHAR}, ",
            "#{desc,jdbcType=VARCHAR})"
    })
    int insert(ZhangyunfeiAccountingRecord record);

    @Select({
            "select",
            "id, gmt_created, gmt_modified, record_time, amount, type, category, `desc`",
            "from zhangyunfei_accounting_record",
            "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "gmt_created", property = "gmtCreated", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "record_time", property = "recordTime", jdbcType = JdbcType.VARCHAR),
            @Result(column = "amount", property = "amount", jdbcType = JdbcType.DOUBLE),
            @Result(column = "type", property = "type", jdbcType = JdbcType.VARCHAR),
            @Result(column = "category", property = "category", jdbcType = JdbcType.VARCHAR),
            @Result(column = "`desc`", property = "`desc`", jdbcType = JdbcType.VARCHAR)
    })
     ZhangyunfeiAccountingRecord selectByPrimaryKey(Long id);

    @Select({
            "select",
            "id, gmt_created, gmt_modified, record_time, amount, type, category, `desc`",
            "from zhangyunfei_accounting_record"
    })
    @Results(id="accountingRecordMap", value={
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "gmt_created", property = "gmtCreated", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "record_time", property = "recordTime", jdbcType = JdbcType.VARCHAR),
            @Result(column = "amount", property = "amount", jdbcType = JdbcType.DOUBLE),
            @Result(column = "type", property = "type", jdbcType = JdbcType.VARCHAR),
            @Result(column = "category", property = "category", jdbcType = JdbcType.VARCHAR),
            @Result(column = "`desc`", property = "`desc`", jdbcType = JdbcType.VARCHAR)
    })
    List<ZhangyunfeiAccountingRecord> selectAll();



    @Select({//根据时间查询
            "select",
            "id, gmt_created, gmt_modified, record_time, amount, type, category, `desc`",
            "from zhangyunfei_accounting_record",
            "where id = #{id,jdbcType=BIGINT}"
    })
   @ResultMap("accountingRecordMap")
    List<ZhangyunfeiAccountingRecord> select(@Param("id") Long id);
    @SelectProvider(type=QueryBuilder.class, method="builderQuery")
    @ResultMap("accountingRecordMap")
    List<ZhangyunfeiAccountingRecord> query(@Param("accountingRecord") ZhangyunfeiAccountingRecord accountingRecord);

    @Update({
            "update zhangyunfei_accounting_record",
            "set",
            "gmt_modified = now(),",
            "record_time = #{recordTime,jdbcType=VARCHAR},",
            "amount = #{amount,jdbcType=DOUBLE},",
            "type = #{type,jdbcType=VARCHAR},",
            "category = #{category,jdbcType=VARCHAR},",
            "`desc` = #{desc,jdbcType=VARCHAR}",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(ZhangyunfeiAccountingRecord record);
}